<template>
  <div class="main coupon-list">
    <!-- 搜索 -->
    <div class="btn-block">
      <router-link v-if="rightsButtons['add']" :to="{name: 'defaultFixedAdd'}">
        <el-button type="success">新建</el-button>
      </router-link>
    </div>
    <!--end-->
    <el-table :data="list" v-loading="listLoading" header-row-class-name="table-header" element-loading-text="给我一点时间" border highlight-current-row>
      <el-table-column align="center" label="序号" type="index" width="60"></el-table-column>
      <el-table-column align="center" label="默认页面" prop="title"></el-table-column>
      <el-table-column align="center" label="有效时间">
        <template slot-scope="scope">
          <span>{{scope.row.startTime}}至{{scope.row.endTime}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="最近一次修改" prop="updatedAt"></el-table-column>
      <el-table-column align="center" label="操作" v-if="rightsButtons['edit']">
        <template slot-scope="scope">
          <router-link v-if="rightsButtons['edit']" :to="{name: 'defaultFixedEdit', params: {row: JSON.stringify(scope.row)}}">
            <el-button type="primary" size="mini">编辑</el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>

    <!--page-->
    <el-pagination
      @current-change="handleCurrentChange"
      :current-page.sync="params.pageIndex"
      :page-size="params.pageSize"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="listTotal">
    </el-pagination>

  </div>
</template>

<script>
  export default {
    name: "defaultFixed",
    data() {
      return {
        params: {
          pageIndex: 1,
          PageSize: 20,
        },
        list: [],
        listTotal: 0,
        listLoading: false,
      }
    },
    created() {
      if (this.$store.getters.cachedViews.length === 0) this.getList()
    },
    activated() {
      this.getList()
    },
    methods: {
      // 首页列表
      getList() {
        this.listLoading = true
        this.request({
          url: '/manage-home-web/home/jump/',
          method: 'get',
          params: this.params
        }).then(({data}) => {
          this.list = data.records || []
          this.listTotal = data.total || 0
          this.listLoading = false
        }).catch(e => {
          this.listLoading = false
        })
      },
      search() {
        this.params.pageIndex = 1
        this.getList()
      },

      handleCurrentChange(val) {
        this.params.pageIndex = val
        this.getList()
      }
    }
  }
</script>

<style scoped>

</style>
